<title>封禁IP列表 - {:getSettingOptionsCache('base.web_site_title') ?: '后台管理系统模板'}</title>
<!--表格插件css-->
<link rel="stylesheet" href="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" type="text/css" href="{:HTTP_STATIC_ADMIN_CDN_URL}css/style.min.css">

<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <header class="card-header">
                    <div class="card-title">封禁IP列表</div>
                </header>
                <div class="card-body">

                    <form id="searchForm" class="row row-cols-lg-auto g-3 align-items-center">
                        <div class="col-12 mb-1">
                            <div class="input-group">
                                <div class="input-group-prepend search-bar">
                                    <button class="btn search-btn btn-default disabled-button-pointer" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">封禁IP</button>
                                </div>
                                <input type="text" class="form-control" autocomplete="off" value="" id="ip" name="ip" placeholder="请输入详细IP地址">
                            </div>
                        </div>
                        <div class="col-12 mb-1">
                            <div class="input-group">
                                <div class="input-group-prepend search-bar">
                                    <button class="btn search-btn btn-default disabled-button-pointer" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">管理员ID</button>
                                </div>
                                <input type="text" class="form-control" autocomplete="off" value="" id="aid" name="aid" placeholder="请输入管理员ID">
                            </div>
                        </div>
                        <div class="col-12 mb-1">
                            <button type="submit" class="btn btn-default me-1 sreach-all"><i class="mdi mdi-magnify"></i> 搜索</button>
                        </div>
                    </form>

                    <div id="toolbar" class="toolbar-btn-action">
                        <button id="add-btn" type="button" class="btn btn-primary me-1">
                            <span class="mdi mdi-plus" aria-hidden="true"></span> 新增IP
                        </button>
                        <button id="del-btn" type="button" class="btn btn-danger">
                            <span class="mdi mdi-window-close" aria-hidden="true"></span> 删除
                        </button>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/layer/src/layer.js"></script>
<!--加载插件-->
<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/lyear-loading.js"></script>
<!--表格插件js-->
<script src="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/bootstrap-table.js"></script>
<script src="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

<script>
    const requestUrl = "{:url('/admin/banip/list')}";
    let objHtml = [
        {
            'title': '编辑',
            'a-class': 'edit-btn',
            'icon': 'mdi-pencil',
            event: function (e, value, row, index) {
                openPage({
                    url: "{:url('/admin/banip/edit')}",
                    param: {
                        id: row.id
                    },
                }, '编辑IP页');
            }
        },
        {
            'title': '删除',
            'a-class': 'del-btn',
            'icon': 'mdi-window-close',
            event: function (e, value, row, index) {
                delUser(row.id);
            }
        },
    ];


    $(function () {
        /**
         * 新增按钮
         */
        $('#add-btn').click(function () {
            openPage({
                url: "{:url('/admin/banip/add')}",
            }, '新增IP页');
        });

        /**
         * 批量 删除按钮
         */
        $('#del-btn').click(function () {
            let selRows = $('#table').bootstrapTable("getSelections");
            if(selRows.length === 0){
                showErrorNotify("请至少选择一行");
                return;
            }
            let postData = [];
            $.each(selRows,function() {
                postData.push(this.id);
            });
            delUser(postData);
        });

    });

    // 操作方法 - 删除
    function delUser(idx) {
        reconfirm({
            url: "{:url('/admin/banip/del')}",
            param: {idx: idx},
            method: 'deletes',
            success: (res) => {
                res.code === 200 && refreshTable();
            }
        }, '确定删除吗？', '请再次确认是否删除？');
    }

    /**
     * 用于演示的列信息
     **/
    const columns = [{
        field: 'example',
        checkbox: true,
        // 是否可视(默认 - true)
        visible: true,
        // 列的宽度
        width: 5,
        // 宽度单位
        widthUnit: 'rem'
    }, {
        field: 'id',
        title: '编号',
        // 使用[align]，[halign]和[valign]选项来设置列和它们的标题的对齐方式。
        // h表示横向，v标识垂直
        align: 'center',
        switchable: false,
        // 列的宽度
        width: 5,
        // 宽度单位
        widthUnit: 'rem'
    }, {
        field: 'ip',
        title: 'IP地址',
        align: 'center',
        width: 35,
        // 宽度单位
        widthUnit: 'rem',
    }, {
        field: 'name',
        title: '创建人',
        align: 'center',
        width: 10,
        // 宽度单位
        widthUnit: 'rem',
        formatter:function(value, row, index, field){
            return (row.aid > 0) ? '<a href="#" className="link-info" onclick="tableCellSearch(\'aid\', \'' + row.aid + '\', 2)">' + value + '</a>' : '-';
        }
    }, {
        field: 'addtime',
        title: '创建时间',
        width: 10,
        // 宽度单位
        widthUnit: 'rem',
        align: 'center',
        formatter:function(value, row, index){
            return (value > 0 ? makeData(value) : '-');
        }
    }, {
        field: 'operate',
        title: '操作',
        align: 'center',
        width: 8,
        // 宽度单位
        widthUnit: 'rem',
        formatter: btnGroup(objHtml),  // 自定义方法
        events: btnEvents(objHtml)
    }];
</script>
<script type="text/javascript" src="/static/admin/js/common/table.js"></script>
<script>
    $(function () {

        $('.sreach-all').click(function () {
            refreshTable();
        });

        $('#searchForm').submit(function(){
            event.preventDefault();
        });
    });
</script>